package com.example.authclient.config;
import com.example.util.utils.DES3EncryptUtil;
import com.example.util.utils.Md5Util;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class MyPasswordEncoder   {
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new PasswordEncoder() {

            @Override
            public boolean matches(CharSequence rawPassword, String encodedPassword) {
                // TODO Auto-generated method stub
                if(((String)rawPassword).equals(encodedPassword) || new DES3EncryptUtil().Decrypt3DES((String)rawPassword).equals(encodedPassword)) return true;
                else {
                return false;
//                    return new DES3EncryptUtil().Encrypt3DES((String) rawPassword).equals(encodedPassword);
                }
//                return Md5Util.encode((String)rawPassword).equals(encodedPassword);
            }

            @Override
            public String encode(CharSequence rawPassword) {
                // TODO Auto-generated method stub
                return (String)rawPassword;
            }
        };
    }
}
